<?php

/**
 * @author Martin Pernica
 * @copyright 2009
 */

class Tools
{

    public static function autoUTF($s)
    {
        // detect UTF-8
        if (preg_match('#[\x80-\x{1FF}\x{2000}-\x{3FFF}]#u', $s))
            return $s;
        // detect WINDOWS-1250
        if (preg_match('#[\x7F-\x9F\xBC]#', $s))
            return iconv('WINDOWS-1250', 'UTF-8', $s);
        // assume ISO-8859-2
        return iconv('ISO-8859-2', 'UTF-8', $s);
    }

    public static function mail($to, $subject, $text, $head = "")
    {
        $predmet = "=?utf-8?B?" . base64_encode(self::autoUTF($subject)) . "?=";
        $head .= "MIME-Version: 1.0\n";
        $head .= "Content-Type: text/plain; charset=\"utf-8\"\n";
        $head .= "Content-Transfer-Encoding: base64\n";
        $zprava = base64_encode(autoUTF($text));
        
        return mail($to, $subject, $text, $head);
    }

}

?>